<?php 

if(!empty($_POST)){
    if(empty($_POST['uname'])){
        exit('用户名不能为空');
    }
    if(empty($_POST['pwd'])){
        exit('密码不能为空');
    }
    $conn = mysql_connect('localhost','root','');
    if(!$conn){
        exit('Could not connect database');
    }else{
        mysql_select_db('test',$conn) || die('Could not connect db test');
        mysql_query('set names "utf8"');
    }
    $pwd = md5($_POST['pwd']);
    //验证用户用户名密码是否正确
    $sql = mysql_query("SELECT * FROM vote_users WHERE name='{$_POST['uname']}' AND password='{$pwd}'");
    if(!$sql){
        exit('登录失败！点击此处 <a href="javascript:history.back(-1);">返回</a> 重试');  
    }
    $userInfo = mysql_fetch_array($sql,MYSQL_ASSOC);
    if(empty($userInfo)){
        exit('用户名或密码错误');
    }
    session_start();
    $_SESSION['uname'] = $userInfo['name'];  
    $_SESSION['uid'] = $userInfo['id']; 
    header("refresh:1;url=index.php");
}

include 'login.html';

?>